/**
 * 分页函数
 * pno--页数
 * psize--每页显示记录数
 * 分页部分是从真实数据行开始，因而存在加减某个常数，以确定真正的记录数
 * 纯js分页实质是数据行全部加载，通过是否显示属性完成分页功能
 **/

function goPage(pno, psize) {
    var itable = document.getElementsByClassName("col-sm-3");
    //var count = pcount;
    var num = itable.length;//表格所有行数(所有记录数)
    // var num = pnum;
    console.log(num);
    var totalPage = 0;//总页数
    var pageSize = psize;//每页显示行数
    //总共分几页
    if (num / pageSize > parseInt(num / pageSize)) {
        totalPage = parseInt(num / pageSize) + 1;
    } else {
        totalPage = parseInt(num / pageSize);
    }
    var currentPage = pno;//当前页数
    var startRow = (currentPage - 1) * pageSize + 1;//开始显示的行 31
    var endRow = currentPage * pageSize;//结束显示的行  40
    endRow = (endRow > num) ? num : endRow;  //40
    console.log(endRow);
    //遍历显示数据实现分页
    for (var i = 1; i < (num + 1); i++) {
        var irow = itable[i - 1];
        if (i >= startRow && i <= endRow) {
            irow.style.display = "block";
        } else {
            irow.style.display = "none";
        }
    }
    var tempStr = "共" + num + "条记录 分" + totalPage + "页 当前第" + currentPage + "页";
    if (currentPage > 1) {
        tempStr += "<a href=\"#\" onClick=\"goPage(" + (1) + "," + psize + ")\">首页</a>";
        tempStr += "<a href=\"#\" onClick=\"goPage(" + (currentPage - 1) + "," + psize + ")\"><上一页</a>"
    } else {
        tempStr += "首页";
        tempStr += "<上一页";
    }
    if (currentPage < totalPage) {
        tempStr += "<a href=\"#\" onClick=\"goPage(" + (currentPage + 1) + "," + psize + ")\">下一页></a>";
        tempStr += "<a href=\"#\" onClick=\"goPage(" + (totalPage) + "," + psize + ")\">尾页</a>";
    } else {
        tempStr += "下一页>";
        tempStr += "尾页";
    }
    document.getElementById("barcon").innerHTML = tempStr;
    ShowCustomerInf();
}
function ShowCustomerInf() {
    var cookies = document.cookie;
    var list = cookies.split("; ");          // 解析出名/值对列表
    for(var i = 0; i < list.length; i++) {
        var arr = list[i].split("=");          // 解析出名和值
        if(arr[0]==='username'){
            console.log(decodeURIComponent(arr[1])) ;   // 对cookie值解码
            document.getElementById("register").innerText=decodeURIComponent(arr[1])+'已登录';
            document.getElementById("exit").style.display='block';
        }
    }
}
function delCookie() {
    document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
}
function changeBg() {
    var bg = ['card text-white bg-primary mb-3','card text-white bg-secondary mb-3',
    'card text-white bg-success mb-3','card text-white bg-danger mb-3',
    'card text-white bg-warning mb-3','card text-white bg-info mb-3',
    'card text-white bg-dark mb-3','card bg-light mb-3'];

}
